package com.game.framework.lock;

import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

public class LooksManager {
    public static final Map<String, ReentrantLock> roleActionLocks = new ConcurrentHashMap<>();
    public static final Map<String, ReentrantLock> actionLocks = new ConcurrentHashMap<>();
    private static final Map<String, ReentrantLock> writeLock = new ConcurrentHashMap<>();


    public static ReentrantLock getWriteLock(Class<?> poClass, Object... id) {
        return writeLock.computeIfAbsent(poClass.getName() + "-" + Arrays.hashCode(id), k -> new ReentrantLock());
    }

    public static ReentrantLock getActionLock(int code, Object... id) {
        return actionLocks.computeIfAbsent(code + "-" + Arrays.hashCode(id), k -> new ReentrantLock());
    }
}

